function searchcodewindow(fn, fw) {
    var win = $.window({
        title: "查询物资编码",
        url: $.webPath() + '/sys/wzbm/search_wzbm?fw=' + (fw == undefined ? "" : fw),
        height: 500,
        width: 1024,
        maximizable: true,
        closable: true,
        closed: false,
        buttons: [
            {
                text: '确定',
                handler: function () {
                    var selected = $(win).find("#search-wzbm-selected-wzbm-grid").datagrid("getData");
                    selected = selected.rows;
                    fn(selected);
                    $(win).dialog('close');
                }
            }
        ]
    });
}



function searchsubjectcodewindow(fn, input, gsId) {
    var win = $.window({
        title: "查询科目代码",
        url: $.webPath() + '/cwgl/kmdm/search_kmdm?gsId=' + gsId,
        height: 500,
        width: 1024,
        maximizable: true,
        closable: true,
        closed: false,
        onMaximize: function () {
            $(this).find("#kmdm_detail_tabs").tabs("resize");
        },
        onRestore: function () {
            $(this).find("#kmdm_detail_tabs").tabs("resize");
        },
        onComplete: function () {
            $(this).find('#searchKmdmDataGrid').datagrid({
                onDblClickRow: function (rowIndex, field, value) {
                    var opts = $(win).window('options');
                    opts.buttons[0].handler();
                }
            });
        },
        buttons: [
            {
                text: '确定',
                handler: function () {
                    var selected = $(win).find("#searchKmdmDataGrid").datagrid("getSelected");
                    //判断是否有下级
                    if (selected.sfxj == "是") {
                        $.messager.alert("提示", "请选择末级科目!");
                    } else {
                        fn(selected, input);
                        $(win).dialog('close');
                    }
                }
            }
        ]
    });
}

function searchkhwindow(fn, ckid, xsgsid, kh_id, cdid, wzggid) {
    var url = $.webPath() + '/xsgl/khgl/kh?ckid=' + ckid + '&xsgsId=' + xsgsid + "&sbgsId=" + kh_id;
    if (cdid != null)
        url += '&cdid=' + cdid;
    if (wzggid != null)
        url += '&wzggid=' + wzggid;
    var win = $.window({
        title: "查询卡号",
        url: url,
        height: 550,
        width: 1000,
        maximizable: true,
        closable: true,
        closed: false,
        buttons: [
            {
                text: '确定',
                handler: function () {
                    $(win).find("#search-kh-selected-kh-grid").edatagrid('saveRow');
                    var selected = $(win).find("#search-kh-selected-kh-grid").edatagrid("getData");
                    selected = selected.rows;
                    fn(selected);
                    $(win).dialog('close');
                }
            }
        ]
    });
}

var htbmStr;
function searcxsdhwindow(fn, xsgsId, sbgsId, khId) {
    var winSec = $.window({
        title: "待结算销售合同",
        url: $.webPath() + '/jsgl/xsjsd/xsd_date?xsgsId=' + xsgsId + '&sbgsId=' + sbgsId + '&khId=' + khId,
        height: 408,
        width: 800,
        maximizable: true,
        buttons: [
            {
                text: '确定',
                handler: function () {
                    var dataDate = $("#xsd_date_grid").datagrid('getSelected');
                    htbmStr = dataDate['HTBM'];
                    var win = $.window({
                        title: "查询销售单",
                        url: $.webPath() + '/jsgl/xsjsd/xsd_search?xsgsId=' + xsgsId + '&sbgsId=' + sbgsId + '&khId=' + khId + '&htbm=' + htbmStr,
                        height: 408,
                        width: 1024,
                        buttons: [
                            {
                                text: '确定',
                                handler: function () {
                                    var selected = $('#xsd_search_grid').datagrid('getChecked');
                                    if (null != selected && "" != selected && selected.length > 0) {
                                        fn(selected);
                                        $(win).dialog('close');
                                    } else {
                                        $.messager.alert("提示", "请选择销售结算记录!", "waring");
                                    }
                                }
                            }
                        ]
                    });
                    $(winSec).dialog('close');
                }
            }
        ]
    })

}

function searcJkdhwindow(fn) {
    var win = $.window({
        title: "查询电子借款单",
        url: $.webPath() + '/sfgl/fksh/fksh_jkd_search',
        height: 400,
        width: 800,
        maximizable: true,
        closable: true,
        closed: false,
        buttons: [
            {
                text: '确定',
                handler: function () {
                    var selected = $('#jkd_search_grid').datagrid('getChecked');
                    fn(selected);
                    $(win).dialog('close');
                }
            }
        ]
    });
}

//查询采购单
function searccgdhwindow(fn, cggsid, gsid, gysid) {
    var win = $.window({
        title: "采购单",
        url: $.webPath() + '/jsgl/cgjsd/cgd_search?cggsId=' + cggsid + '&gsId=' + gsid + '&gysid=' + gysid,
        height: 400,
        width: 1024,
        maximizable: true,
        iconCls: 'icon-add2',
        closable: true,
        closed: false,
        buttons: [
            {
                text: '确定',
                handler: function () {
                    var selected = $('#cgd_search_grid').datagrid('getChecked');
                    if (null != selected && "" != selected && selected.length > 0) {
                        fn(selected);
                        $(win).dialog('close');
                    } else {
                        $.messager.alert("提示", "请选择采购结算记录!", "waring");
                    }
                }
            }
        ]
    });
}

function searcPjhwindow(fn) {
    var win = $.window({
        title: "查询票据",
        url: $.webPath() + '/sfgl/fksh/fksh_pj_search',
        height: 400,
        width: 750,
        maximizable: true,
        closable: true,
        closed: false,
        buttons: [
            {
                text: '确定',
                handler: function () {
                    var selected = $('#pj_search_grid').edatagrid('getChecked');
                    fn(selected);
                    $(win).dialog('close');
                }
            }
        ]
    });
}

function searcXyzwindow(fn) {
    var win = $.window({
        title: "查询信用证",
        url: $.webPath() + '/sfgl/fksh/fksh_xyz_search',
        height: 400,
        width: 750,
        maximizable: true,
        closable: true,
        closed: false,
        buttons: [
            {
                text: '确定',
                handler: function () {
                    var selected = $('#xyz_search_grid').datagrid('getChecked');
                    fn(selected);
                    $(win).dialog('close');
                }
            }
        ]
    });
}

//查询物流单
function searchwldwindow(fn, sydwId, sydwGsId) {
    var win = $.window({
        title: "查询物流单",
        url: $.webPath() + '/jsgl/wljsd/wld_search?sydwId=' + sydwId + "&sydwGsId=" + sydwGsId,
        height: 450,
        width: 1024,
        //maximizable: true,
        iconCls: 'icon-add2',
        closable: true,
        closed: false,
        buttons: [
            {
                text: '确定',
                handler: function () {
                    var selected = $('#wld_search_grid').datagrid('getChecked');
                    var flag = false;
                    $.each(selected, function (i, val) {
                        if (val['czzt'] == "null") {
                            $.messager.alert("提示", "请选择可结算的物流单!", "waring");
                            flag = true;
                            return false;
                        }
                    });
                    if (!flag) {
                        fn(selected);
                        $(win).dialog('close');
                    }
                }
            }
        ]
    });
}